// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso;

import gnu.trove.map.hash.TLongObjectHashMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import zombie.iso.areas.IsoBuilding;
import zombie.iso.areas.IsoRoom;

public final class LotHeader {
    public int cellX;
    public int cellY;
    public int width = 0;
    public int height = 0;
    public int levels = 0;
    public int version = 0;
    public final HashMap<Integer, RoomDef> Rooms = new HashMap();
    public final TLongObjectHashMap<RoomDef> RoomByMetaID = new TLongObjectHashMap<>();
    public final ArrayList<RoomDef> RoomList = new ArrayList();
    public final ArrayList<BuildingDef> Buildings = new ArrayList();
    public final TLongObjectHashMap<BuildingDef> BuildingByMetaID = new TLongObjectHashMap<>();
    public final HashMap<Integer, IsoRoom> isoRooms = new HashMap();
    public final HashMap<Integer, IsoBuilding> isoBuildings = new HashMap();
    public boolean bFixed2x;
    protected final ArrayList<String> tilesUsed = new ArrayList();

    public int getHeight() {
        return this.height;
    }

    public int getWidth() {
        return this.width;
    }

    public int getLevels() {
        return this.levels;
    }

    public IsoRoom getRoom(int roomID) {
        RoomDef roomDef = (RoomDef)this.Rooms.get(roomID);
        if (!this.isoRooms.containsKey(roomID)) {
            IsoRoom isoRoom = new IsoRoom();
            isoRoom.rects.addAll(roomDef.rects);
            isoRoom.RoomDef = roomDef.name;
            isoRoom.def = roomDef;
            isoRoom.layer = roomDef.level;
            IsoWorld.instance.CurrentCell.getRoomList().add(isoRoom);
            if (roomDef.building == null) {
                roomDef.building = new BuildingDef();
                roomDef.building.ID = this.Buildings.size();
                roomDef.building.rooms.add(roomDef);
                roomDef.building.CalculateBounds(new ArrayList());
                roomDef.building.metaID = roomDef.building.calculateMetaID(this.cellX, this.cellY);
                this.Buildings.add(roomDef.building);
            }

            int _int = roomDef.building.ID;
            this.isoRooms.put(roomID, isoRoom);
            if (!this.isoBuildings.containsKey(_int)) {
                isoRoom.building = new IsoBuilding();
                isoRoom.building.def = roomDef.building;
                this.isoBuildings.put(_int, isoRoom.building);
                isoRoom.building.CreateFrom(roomDef.building, this);
            } else {
                isoRoom.building = (IsoBuilding)this.isoBuildings.get(_int);
            }

            return isoRoom;
        } else {
            return (IsoRoom)this.isoRooms.get(roomID);
        }
    }

    @Deprecated
    public int getRoomAt(int x, int y, int z) {
        for (Entry entry : this.Rooms.entrySet()) {
            RoomDef roomDef = (RoomDef)entry.getValue();

            for (int _int = 0; _int < roomDef.rects.size(); _int++) {
                RoomDef.RoomRect roomRect = (RoomDef.RoomRect)roomDef.rects.get(_int);
                if (roomRect.x <= x && roomRect.y <= y && roomDef.level == z && roomRect.getX2() > x && roomRect.getY2() > y) {
                    return (Integer)entry.getKey();
                }
            }
        }

        return -1;
    }

    public void Dispose() {
        this.Rooms.clear();
        this.RoomByMetaID.clear();
        this.RoomList.clear();
        this.Buildings.clear();
        this.BuildingByMetaID.clear();
        this.isoRooms.clear();
        this.isoBuildings.clear();
        this.tilesUsed.clear();
    }
}
